//
//  Statuse.swift
//  ZYBWeibo
//
//  Created by xthink4 on 16/3/11.
//  Copyright © 2016年 zyb. All rights reserved.
//

import UIKit
var statusesUrl="https://api.weibo.com/2/statuses/friends_timeline.json"
class StatuseModel: NSObject {
    //微博创建时间
    var created_at:String!
    //微博id
    var id:Int!
    //微博内容
    var text:String!
    //微博来源
    var source:String!
    //用户信息
    var user:UserModel!
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    ///获取首页微博信息（使用kvo字典转模型）
    class func DownLoadWeiBoData(paraDict:[String:AnyObject],completion:(arr:NSArray?)->Void){
        NetWorkTools.requestJSON(.GET, urlString: statusesUrl, parameters:paraDict) { (JSON) -> Void in
            
            let statuseDict:Dictionary<String,AnyObject>=JSON as! Dictionary
           
            let statuseArr:NSArray=statuseDict["statuses"] as! NSArray
            let weiboArr:NSMutableArray=NSMutableArray()
            for index in statuseArr{
                let statuse:StatuseModel=StatuseModel()
                let weiboDict:Dictionary<String,AnyObject>=index as! Dictionary
                statuse.setValuesForKeysWithDictionary(weiboDict)
                if weiboDict["user"] != nil{
                    let userDic = weiboDict["user"] as!Dictionary as [String:AnyObject]
                    let userInfo=UserModel()
                    userInfo.setValuesForKeysWithDictionary(userDic)
                    statuse.user = userInfo
                }
                weiboArr.addObject(statuse)
            }
            completion(arr:weiboArr)
        }
    }
}
